#pragma once
#include <algorithm>
#include <cmath>
#include <utility>
#include <cstdio>
#include <vector>
#include <iostream>
#include "src/TGPoint.h"

const int INTERSECTION = 1;
const int NOT = 2;
const int OVERLAP = 3;
const int COMMONLINE = 4;


class TGLine {
public:
    std::pair<TGPoint, TGPoint>data;
    TGLine() = default;
    TGLine(const TGPoint& st, const TGPoint& ed) : data(st, ed){}
    TGLine(double x1, double y1, double x2, double y2): data({x1, y1}, {x2, y2}) {}
    TGLine& operator = (const TGLine&);
};
bool intersection(const TGLine& l1, const TGLine& l2, TGPoint& p);
double direction(const TGPoint& p1, const TGPoint& p2, const TGPoint& p3);
bool isColinePointOnSegment(const TGLine&, const TGPoint& p3);
bool commonLine(const TGLine& l1, const TGPoint& p);
bool parallel(const TGLine& l1, const TGLine& l2);
int commonLineAndIntersection(const TGLine& l1, const TGLine& l2);
int isIntersection(const TGLine& l1, const TGLine& l2);
//计算两条直线的交点
bool lineIntersect(const TGLine& l1, const TGLine& l2, TGPoint& p);
//计算点到折线距离,并返回垂足坐标
std::pair<TGPoint, double> pdist(const TGPoint&, const TGLine&);
//计算定点到折线组距离，并返回垂足坐标
std::pair<TGPoint, double> pdist(const TGPoint&, std::vector<TGPoint>&);